package com.kongwg.java;

import org.junit.Test;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author kongwg
 * @create 2020-12-16 8:56
 */
public class ConcurrentHashMapTest {

    @Test
    public void test(){
        ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();
        concurrentHashMap.put("AA",123);
        concurrentHashMap.put("BB",456);
        System.out.println(concurrentHashMap);


    }

    @Test
    public void test2(){
        HashMap map = new HashMap();
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        TreeMap treeMap = new TreeMap();
        Hashtable hashtable = new Hashtable();

        map.put("AA",123);
        map.put("BB",234);
        map.put("CC",345);
        map.put("DD",567);
        map.put("EE",890);

        Set set = map.entrySet();
        Iterator iterator = set.iterator();
        while (iterator.hasNext()){
            Object obj = iterator.next();

            Map.Entry entry = (Map.Entry) obj;
            System.out.println(entry.getKey() + "---" + entry.getValue());
        }

        System.out.println();
        //方式二
        Set set1 = map.keySet();
        Iterator iterator1 = set1.iterator();
        while (iterator1.hasNext()){
            Object key = iterator1.next();
            Object value = map.get(key);
            System.out.println(key + "---" + value);
        }



    }
}
